const app = getApp()

Component({
  properties: {
    isShow: {
      type: Boolean,
      value: false
    },
    integralNum: {
      type: Number
    }
  },
  data: {
    lang: app.globalData.language,

    coinShow: false, //金币对象是否显示，用于重置动画时，隐藏对象
    //大金币动画
    bgCoinAnimation:{},
    bgTextAnimation:{},
    //小金币动画
    coinAnimation1:{},
    coinAnimation2:{},
    coinAnimation3:{},
    coinAnimation4:{},
    coinAnimation5:{},
    coinAnimation6:{},
    coinAnimation7:{},
  },
  methods: {
    //动画
    animation(){
      let audio = wx.createInnerAudioContext({});
      audio.src = 'http://demo.test.tb21.cn/front-end/uob-html/uob_art/10947.mp3';
      audio.play();
      this.setData({
        coinShow: false,
      })
      this._bgAnimation();
      this._smallAnimation();
    },
    //大金币动画
    _bgAnimation(){
      let animation = wx.createAnimation({
        duration:1000,
        timingFunction: 'ease-in-out',
      })
      let animation1 = wx.createAnimation({
        duration:1000,
        timingFunction: 'ease-in-out',
      })
      this.timer =  setTimeout(()=>{
        animation.translate3d(0,30,0).step().translate3d(0,0,0).step().rotate(80).step({duration:400}).rotate(0).step({duration:500})
        this.setData({
          bgCoinAnimation: animation.export()
        })
      },100)
      setTimeout(()=>{
        animation.opacity(0).scale(4).step()
        animation1.opacity(0).scale(4).step()
        this.setData({
          bgCoinAnimation: animation.export(),
          bgTextAnimation: animation1.export()
        })
      },3000)
      this.timer = setTimeout(()=>{
        animation1.opacity(1).scale(2).step().scale(1).step()
        this.setData({
          bgTextAnimation: animation1.export()
        })
      },500)
    },
    //小金币动画
    _smallAnimation(){
      let animation = wx.createAnimation({
        duration:1000,
        timingFunction: 'ease-in-out',
      })
      animation.translate3d(0,30,0).step().translate3d(0,0,0).step()
      setTimeout(()=>{
        this.setData({
          coinAnimation1: animation
        })
      },300)
      setTimeout(()=>{
        this.setData({
          coinAnimation2: animation
        })
      },500)
      setTimeout(()=>{
        this.setData({
          coinAnimation3: animation
        })
      },600)
      setTimeout(()=>{
        this.setData({
          coinAnimation4: animation
        })
      },700)
      setTimeout(()=>{
        this.setData({
          coinAnimation5: animation
        })
      },800)
      setTimeout(()=>{
        this.setData({
          coinAnimation6: animation
        })
      },900)
      setTimeout(()=>{
        this.setData({
          coinAnimation7: animation.export()
        })
      },1000)
      //小金币掉落动画
      setTimeout(()=>{
        animation.translate3d(0,1000,0).step()
        this.setData({
          coinAnimation1: animation,
          coinAnimation2: animation,
          coinAnimation3: animation,
          coinAnimation4: animation,
          coinAnimation5: animation,
          coinAnimation6: animation,
          coinAnimation7: animation,
        })
      },3000)
      //动画结束，重置动画初始位置
      setTimeout(()=>{
        let animation = wx.createAnimation({
          duration:300,
          timingFunction: 'ease-in-out',
        })
        let animation2 = wx.createAnimation({
          duration:300,
          timingFunction: 'ease-in-out',
        })
        animation.translate3d(0,-1000,0).step().export();
        animation2.translate3d(0,-1000,0).step().scale(1).step().export();
        this.setData({
          bgCoinAnimation: animation2.export(),
          coinAnimation1: animation.export(),
          coinAnimation2: animation.export(),
          coinAnimation3: animation.export(),
          coinAnimation4: animation.export(),
          coinAnimation5: animation.export(),
          coinAnimation6: animation.export(),
          coinAnimation7: animation.export()
        })
      },4000)
    }
  }
});
